package com.jay.syncdrawing.ui;

import com.jay.syncdrawing.AppManager;
import com.jay.syncdrawing.R;
import com.jay.syncdrawing.R.id;
import com.jay.syncdrawing.R.layout;
import com.jay.syncdrawing.R.menu;
import com.jay.syncdrawing.utils.NetworkUtil;
import com.jay.syncdrawing.utils.ToastUtils;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class ServerActivity extends Activity {
	private Intent intent = new Intent();
	private EditText et_ip,et_port;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_server);
		AppManager.getAppManager().addActivity(this);
		findView();
	}

	private void findView() {
		et_ip = (EditText) findViewById(R.id.et_ip);
		et_port = (EditText) findViewById(R.id.et_port);
	}

	public void onClick(View v) {
		String ip = et_ip.getText().toString();
		String port = et_port.getText().toString();
		if(ip != null && port != null && !"".equals(ip) && !"".equals(port)){
			intent.setClass(this, MainActivity.class);
			intent.putExtra("ip", ip);
			intent.putExtra("port", Integer.parseInt(port));
			startActivity(intent);
		}else{
			//这里文字影应写在string.xml里
			ToastUtils.showToast("请输入服务器信息!");
		}
		
		//可以不用，同局域网就行
//		if(NetworkUtil.isNetworkAvailable(this)){
//			
//		}else{
//			showAlterDialog();
//		}
	}

	private void showAlterDialog(){  
		Dialog alterDialog = new AlertDialog.Builder(this).  
				setTitle("警告").  
				setMessage("当前网络没有正常连接，请连接后再操作.").  
				setIcon(android.R.drawable.ic_dialog_alert).  
				setPositiveButton("确定", new DialogInterface.OnClickListener() {  

					@Override  
					public void onClick(DialogInterface dialog, int which) {  
						// TODO Auto-generated method stub  
						dialog.dismiss();  
					}  
				}).  
				create();  
		alterDialog.show();  
	}
}
